Gleb Smirinoff contributes vertical speed calculation for use with subrip.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 22 Mar 2015 00:31:17 +0000 (00:31 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 22 Mar 2015 00:31:17 +0000 (00:31 +0000)
(There are probably edge cases about tracks with and without valid alt....)

gpsbabel/defs.h
gpsbabel/subrip.cc
gpsbabel/waypt.cc
gpsbabel/xmldoc/formats/options/subrip-format.xml

index 2c284d78941d334d4a86c7296e2d1e8bdcda558e..6a06920db6bef585c659029c02d0128889b359cc 100644 (file)
@@ -866,6 +866,7 @@ void waypt_status_disp(int total_ct, int myct);
 double waypt_time(const Waypoint* wpt);
 double waypt_speed(const Waypoint* A, const Waypoint* B);
 double waypt_speed_ex(const Waypoint* A, const Waypoint* B);
+double waypt_vertical_speed(const Waypoint* A, const Waypoint* B);
 double waypt_course(const Waypoint* A, const Waypoint* B);
 double waypt_distance(const Waypoint* A, const Waypoint* B);
 double waypt_distance_ex(const Waypoint* A, const Waypoint* B);
index ffd95f6e3950915a0026ccae4b517938228affa2..9490aadf48dfef31070818f451f323a67265d328 100644 (file)
@@ -33,6 +33,7 @@ static time_t time_offset;
 static int stnum;
 static gbfile* fout;
 static const Waypoint* prevwpp;
+static double vspeed;
 
 /* internal helper functions */
 
@@ -106,6 +107,9 @@ subrip_prevwp_pr(const Waypoint* waypointp)
         else
           gbfprintf(fout, "   -");
         break;
+      case 'v':
+        gbfprintf(fout, "%2.2f", vspeed);
+        break;
       case 't':
         {
           QTime t = prevwpp->GetCreationTime().toUTC().time();
@@ -159,6 +163,10 @@ subrip_trkpt_pr(const Waypoint* waypointp)
    * associated waypoint plus that of the following one.
    * Since we get waypoints one at a time, the only way is to store one and
    * defer processing until we get the next one.
+   *
+   * To determine vertical speed we need to have not only previous waypoint,
+   * but also pre-previous, so we calculate vspeed right before forgetting
+   * the previous.
    */
   if ((stnum == 1) && (time_offset == 0))
     /*
@@ -174,6 +182,7 @@ subrip_trkpt_pr(const Waypoint* waypointp)
 
   if (prevwpp) {
     subrip_prevwp_pr(waypointp);
+    vspeed = waypt_vertical_speed(waypointp, prevwpp);
   }
   prevwpp = waypointp;
 }
@@ -191,6 +200,7 @@ subrip_wr_init(const char* fname)
   time_offset = 0;
 
   prevwpp = NULL;
+  vspeed = 0;
 
   if ((opt_gpstime != NULL) && (opt_gpsdate != NULL)) {
     time(&gpstime_t);
index 3cdbcdbe025503614ef39c2ffeb1e3d154f8b943..15706c5a12adeed09222af3da0a8a4ef83224b47 100644 (file)
@@ -541,6 +541,29 @@ waypt_speed(const Waypoint* A, const Waypoint* B)
   }
 }
 
+/*
+ * Calculates the vertical speed between points "A" and "B"
+ * the result comes in meters per second and can be negative.
+ */
+
+double
+waypt_vertical_speed(const Waypoint* A, const Waypoint* B)
+{
+  double altitude, time;
+
+  altitude = A->altitude - B->altitude;
+  if (altitude == 0) {
+    return 0;
+  }
+
+  time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0;
+  if (time > 0) {
+    return (altitude / time);
+  } else {
+    return 0;
+  }
+}
+
 /*
  * Calculates "Course True" from A to B
  */
index 2f2b27e96ee48900bb6091e342cec28e5ba5da34..1d017a6787d918e580a019572af128808b6c5dbf 100644 (file)
   <entry>%e</entry>
   <entry>elevation in meters</entry>
 </row>
+<row>
+  <entry>%v</entry>
+  <entry>vertical speed in m/s</entry>
+</row>
 <row>
   <entry>%t</entry>
-  <entry>tiomestamp</entry>
+  <entry>timestamp</entry>
 </row>
 <row>
   <entry>%l</entry>